home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 11 Learning / 01 Manslow / GAPBILExample / CPBIL.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-07  |  2.0 KB  |  79 lines

  1. //GAPBILExample
  2. //Copyright John Manslow
  3. //29/09/2001
  4.  
  5. #ifndef _CPBIL_
  6. #define _CPBIL_
  7.  
  8. class CPBIL
  9. {
  10. public:
  11.  
  12.     CPBIL(
  13.                             const unsigned long,            //Population size
  14.                             const unsigned long                //Chromosome length
  15.                 );
  16.  
  17.     ~CPBIL();
  18.  
  19.     //One of the two functions required to make the PBIL work.Calling this function returns one member of
  20.     //the population to allow its fintess to be evaluated
  21.     double *pdGetChromosomeForEvaluation(void);
  22.  
  23.     //Called after the fitness evaluation to update the fitness statistics of teh population 
  24.     void SetFitness(const double);
  25.  
  26.     //Load and save the status of the PBIL
  27.     int Save(const char*const);
  28.     int Load(const char*const);
  29.  
  30.     //Returns a pointer to the best performing chromosome found so far
  31.     double *pdGetBestChromosome(void);
  32.  
  33.     //Returns the performance of the best chromosome found so far
  34.     double dGetBestPerformance(void);
  35.  
  36. private:
  37.  
  38.     //Creates a population by sampling from the gene probabilities
  39.     void CreatePopulation(void);
  40.  
  41.     //Allocates and deallocates memory to store the population, fitness statisticas, etc.
  42.     void AllocateMemory(void);
  43.     void DeallocateMemory(void);
  44.  
  45.     //Mutates the chromosome probability vector
  46.     void Mutate(void);
  47.  
  48.     //The per-gene mutation probability
  49.     double dMutationRate;
  50.  
  51.     //Population size and chromosome length
  52.     unsigned long ulPopulationSize;
  53.     unsigned long ulChromosomeLength;
  54.  
  55.     //Points to the population
  56.     double **ppdGenes;
  57.  
  58.     //Points to the fitness statistics
  59.     double *pdFitnesses;
  60.  
  61.     //Points to the vector of gene probabilities from which the population is sampled
  62.     double *pdGeneProbabilities;
  63.  
  64.     //Controls the rate at which the PBIL learns
  65.     double dAdaptationRate;
  66.  
  67.     //The fitness of the best chromosome found so far and the chromosome itself
  68.     double dBestFitness;
  69.     double *pdBestChromosome;
  70.  
  71.     //The position of the chromosome currently being evaluated in the population
  72.     unsigned long ulWorkingChromosome;
  73.  
  74.     //The number of fitness evaluations so far
  75.     unsigned long ulIteration;
  76.  
  77. };
  78.  
  79. #endif